package com.ruoyi.project.income.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.income.domain.BinsMerchantAccount;
import com.ruoyi.project.income.service.IBinsMerchantAccountService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商户账户信息Controller
 * 
 * @author admin
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/income/account")
public class BinsMerchantAccountController extends BaseController
{
    @Autowired
    private IBinsMerchantAccountService binsMerchantAccountService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
     * 查询商户账户信息列表
     */
    @PreAuthorize("@ss.hasPermi('income:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinsMerchantAccount binsMerchantAccount)
    {
        startPage();
        if(null==binsMerchantAccount.getMerchantDeptId()){
            binsMerchantAccount.setMerchantDeptId(getCommonDeptId());
        }
        List<BinsMerchantAccount> list = binsMerchantAccountService.selectBinsMerchantAccountList(binsMerchantAccount);
        if (list!=null){
            list.forEach(item -> {
                SysDept sysdept = sysDeptService.selectDeptById(item.getMerchantDeptId());
                if (sysdept!=null){
                    item.setMerchantDeptName(sysdept.getDeptName());
                }
            });
        }
        return getDataTable(list);
    }

    /**
     * 导出商户账户信息列表
     */
    @PreAuthorize("@ss.hasPermi('income:account:export')")
    @Log(title = "商户账户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinsMerchantAccount binsMerchantAccount)
    {
        List<BinsMerchantAccount> list = binsMerchantAccountService.selectBinsMerchantAccountList(binsMerchantAccount);
        ExcelUtil<BinsMerchantAccount> util = new ExcelUtil<BinsMerchantAccount>(BinsMerchantAccount.class);
        util.exportExcel(response, list, "商户账户信息数据");
    }

    /**
     * 获取商户账户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('income:account:query')")
    @GetMapping(value = "/{merchantDeptId}")
    public AjaxResult getInfo(@PathVariable("merchantDeptId") Long merchantDeptId)
    {
        return success(binsMerchantAccountService.selectBinsMerchantAccountByMerchantDeptId(merchantDeptId));
    }

    /**
     * 新增商户账户信息
     */
    @PreAuthorize("@ss.hasPermi('income:account:add')")
    @Log(title = "商户账户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinsMerchantAccount binsMerchantAccount)
    {
        return toAjax(binsMerchantAccountService.insertBinsMerchantAccount(binsMerchantAccount));
    }

    /**
     * 修改商户账户信息
     */
    @PreAuthorize("@ss.hasPermi('income:account:edit')")
    @Log(title = "商户账户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinsMerchantAccount binsMerchantAccount)
    {
        return toAjax(binsMerchantAccountService.updateBinsMerchantAccount(binsMerchantAccount));
    }

    /**
     * 删除商户账户信息
     */
    @PreAuthorize("@ss.hasPermi('income:account:remove')")
    @Log(title = "商户账户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantDeptIds}")
    public AjaxResult remove(@PathVariable Long[] merchantDeptIds)
    {
        return toAjax(binsMerchantAccountService.deleteBinsMerchantAccountByMerchantDeptIds(merchantDeptIds));
    }
}
